#include "stdafx.h"
#include <MyControls/TimeScaleOut.h>
#include <MyControls/Timeline.h>
#include <MyControls/Resource.h>
#include <MyControls/App.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

namespace My {

TimeScaleOut::TimeScaleOut(Timeline & t)
	: GlyphButton("ZoomOut", "ZoomOutMask"), m_Timeline(t)
{
	m_Timeline.Add(this);
}

String TimeScaleOut::Hint() const
{
	return GetApp().LoadString(IDS_TIMELINE_ZOOM_OUT);
}

void TimeScaleOut::ProcessEvent(My::Event & e)
{
	if (e.Is<Sequence::PreviewFrameChange>())
		return;
	if (e.Is<CommandEvent>()) {
		CommandEvent & event = e.As<CommandEvent>();
		if (event.m_nID == ID_TIMELINE_ZOOM_OUT) {
			HandleClick();
			event.m_Handled = true;
			return;
		}
	}
	else if (e.Is<UpdateCommandUIEvent>()) {
		UpdateCommandUIEvent & event = e.As<UpdateCommandUIEvent>();
		if (event.m_nID == ID_TIMELINE_ZOOM_OUT) {
			event.m_pCmdUI->Enable(ControlEnabled(this));
			event.m_Handled = true;
			return;
		}
	}
	else if (e.Is<Sequence::Event>() || e.Is<Timeline::Event>()) {
		Invalidate();
		return;
	}
	GlyphButton::ProcessEvent(e);
}

bool TimeScaleOut::Enabled() const
{
	return !m_Timeline.IsEmpty() &&
		m_Timeline.GetTimeScale() > m_Timeline.GetMinTimeScale();
}

void TimeScaleOut::HandleClick()
{
	m_Timeline.SetTimeScale(m_Timeline.GetTimeScale() / 2);
}

} // My
